<template>
  <div class="updateForm">  
    <el-dialog title="增加新景点" :visible="dialogFormVisible" @close="$emit('closeDialog')" width="50%">
      <el-form :label-position="labelPosition" label-width="150px" :model="addForm">
        <el-form-item label="标题" :required="true">
          <el-input v-model="addForm.title"></el-input>
        </el-form-item>
        <el-form-item label="内容" :required="true">
          <el-input v-model="addForm.content"></el-input>
        </el-form-item>
        <el-form-item label="原价" :required="true">
          <el-input v-model="addForm.price"></el-input>
        </el-form-item>
        <el-form-item label="折后价" :required="true">
          <el-input v-model="addForm.priceDiscount"></el-input>
        </el-form-item>
        <el-form-item label="排序" :required="true">
          <el-input v-model="addForm.sort"></el-input>
        </el-form-item>
        <label id="la" for>主显示图</label>
        <imgUpload @uploaded="uploaded" @uploadFail="uploadFail" :size="500"></imgUpload>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="$emit('closeDialog')">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import imgUpload from "../imgUpload";
export default {
  name: "AttrAdd",
  props: ["dialogFormVisible"],
  data() {
    return {
      labelPosition: "right",
      addForm: {
        title: "",
        content: "",
        path: "",
        price: "",
        priceDiscount: "",
        sort: ""
      },
      imageUrl: "",
      OldImageUrl: ""
      // uploadApi: "http://127.0.0.1:8000/api/img/uploadImg"
    };
  },
  methods: {
    submit: async function() {
      let data = await this._axios
        .post("/ycwAdmin/attraction/addAttr", this.addForm)
        .then(data => data.data);
      console.log(data);
      if (data.code) {
        this.$message({
          message: `${data.msg}`,
          type: "success"
        });
        this.$emit("refresh");
        this.addForm = {
          title: "",
          content: "",
          path: "",
          price: "",
          priceDiscount: "",
          sort: ""
        };
      } else {
        this.$message({
          message: `${data.msg}`,
          type: "error"
        });
      }
      //   }
    },
    uploaded: function(res) {
      console.log(this.OldImageUrl);
      this.OldImageUrl = this.addForm.path;
      this.addForm.path = res.path;
    },
    uploadFail: function(res) {
      console.log(res);
      //上传错误处理
    }
  },
  components: {
    imgUpload
  }
};
</script>

<style lang="scss">
.updateForm {
  #la {
    display: inline-block;
    margin-bottom: 10px;
  }
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409eff;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
}
</style>